package com.itgungnir.designpattern.state;

public class CandyMachine {
	private State moneyInsertedState;
	private State noMoneyState;
	private State noCandyState;
	private State candyPoppingState;
	private State winnerState;

	private State state;
	private int candyCount;

	public CandyMachine(int candyCount) {
		this.moneyInsertedState = new MoneyInsertedState(this);
		this.noMoneyState = new NoMoneyState(this);
		this.noCandyState = new noCandyState(this);
		this.candyPoppingState = new CandyPoppingState(this);
		this.winnerState = new WinnerState(this);
		this.state = noMoneyState;
		this.candyCount = candyCount;
	}

	// 投币
	public void insertMoney() {
		this.state.onMoneyInserted();
	}

	// 退钱
	public void returnMoney() {
		this.state.onMoneyReturned();
	}

	// 转动摇把
	public void turnCrank() {
		this.state.onCrankTurned();
	}

	// 发放糖果
	public void popCandy() {
		this.state.onCandyPoped();
	}

	public State getMoneyInsertedState() {
		return moneyInsertedState;
	}

	public void setMoneyInsertedState(State moneyInsertedState) {
		this.moneyInsertedState = moneyInsertedState;
	}

	public State getNoMoneyState() {
		return noMoneyState;
	}

	public void setNoMoneyState(State noMoneyState) {
		this.noMoneyState = noMoneyState;
	}

	public State getNoCandyState() {
		return noCandyState;
	}

	public void setNoCandyState(State noCandyState) {
		this.noCandyState = noCandyState;
	}

	public State getCandyPoppingState() {
		return candyPoppingState;
	}

	public void setCandyPoppingState(State candyPoppingState) {
		this.candyPoppingState = candyPoppingState;
	}

	public State getWinnerState() {
		return winnerState;
	}

	public void setWinnerState(State winnerState) {
		this.winnerState = winnerState;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public int getCandyCount() {
		return candyCount;
	}

	public void setCandyCount(int candyCount) {
		this.candyCount = candyCount;
	}
}